<template>
  <a-scrollbar style="height: 300px; overflow: auto">
    <div v-if="['WAIT_SCHEDULE', 'EXECUTING', 'WAIT_VERIFY', 'FINISHED', 'NEGOTIATE_TERMINATED', 'TERMINATED'].includes(taskInfo.status)">
      <div v-for="(item, index) of deliveryDataList" :key="index">
        <div class="title-bar">
          <a-space>
            <div>{{ nodeMap[item.nodeType] }}</div>
            <div class="common-text" style="font-weight: 200">{{ $extract(item, 'executer.name') }}</div>
            <span style="font-size: 13px; font-weight: 200">{{ getItemContent(item) }}</span>
          </a-space>
        </div>
        <div class="clearfix" v-if="taskInfo.type != 'SHOOT_VIDEO'">
          <div class="fl" v-if="item.fileList[0]">
            <a-image class="mr10 mb10 cursor" @click="showImgProview(item.fileList, i)" :preview="false" width="60" height="60" :src="imgItem.url" v-for="(imgItem, i) of item.fileList" :key="i" />
          </div>
          <div style="width: 100px" v-else>
            <a-empty description="暂无交付数据" />
          </div>
        </div>
        <div class="clearfix" v-else>
          <div class="fl" v-for="(videoItem, i) of item.fileList" :key="i">
            <video :src="videoItem.url" style="width: 160px; height: 160px; margin: 0 10px 10px 0" width="160" height="160" controls></video>
          </div>
        </div>
      </div>

      <div v-if="taskInfo.deliveryAttList && taskInfo.deliveryAttList[0]">
        <div class="title-bar">
          <a-space>
            <div>附件</div>
            <div class="highlight cursor" style="font-weight: 200" @click="downloadMul(taskInfo.deliveryAttList, '任务附件')">下载附件</div>
          </a-space>
        </div>
        <div>
          <div class="att-item" v-for="(item, index) of taskInfo.deliveryAttList" :key="index">{{ item.name }}</div>
        </div>
      </div>
    </div>
    <a-empty v-else description="暂无数据" />

    <a-image-preview-group v-model:visible="visible" v-model:current="current" infinite :srcList="previewList" />
  </a-scrollbar>
</template>

<script lang="ts" setup>
  import { defineComponent, ref, onMounted } from 'vue'
  import { downloadMul } from '@/utils'
  import { nodeMap, shootTypeMap, deliveryMap } from '../addOrEdit/map'
  import _ from 'lodash-es'
  let deliveryDataList: any = ref([])
  let taskInfo: any = ref({})
  let current = ref(0)
  let previewList = ref([])
  let visible = ref(false)
  const setRes = (info: any) => {
    taskInfo.value = info
    // // 交付数据
    let fileListArr = info.deliveryFileList || []
    // 节点数据
    let arr = info.taskRequire.taskNodeList || []
    arr.forEach((e: any) => {
      e.fileList = fileListArr.filter((el: any) => el.nodeType == e.nodeType)
    })
    deliveryDataList.value = arr
  }

  const showImgProview = (list: any, i: number) => {
    if (list.length > 0) {
      current.value = i
      visible.value = true
      previewList.value = list.map((el: any) => el.url)
    }
  }

  const getItemContent = (data: any) => {
    let arr = data.taskContentList || []
    return arr.map((e: any) => `${deliveryMap[e.contentType]}×${e.quantity}`).join('，')
  }

  defineExpose({ setRes })
</script>

<style lang="less" scoped>
  .att-item {
    width: 100%;
    background-color: #d7d7d7;
    padding: 3px 15px 3px 5px;
    border-radius: 3px;
    margin-top: 10px;
    font-size: 12px;
  }

  .img-title {
    // position: absolute;
    // top: 0;
    // left: 0;
    width: 100%;
    background-color: #d7d7d7;
    // color: white;
    z-index: 10;
    opacity: 0.9;
    font-size: 10px;
  }

  .post-con {
    width: 100%;
    padding: 5px;
    background-color: #d7d7d7;
  }

  .box-img-con {
    float: left;
    width: 80px;
    height: 80px;
    position: relative;
    margin: 0 10px 10px 0;
    &:hover {
      .mask {
        display: block;
      }
    }
    .mask {
      height: 80px;
      width: 80px;
      position: absolute;
      top: 0;
      left: 0;
      display: none;
      z-index: 1;
      background: rgba(0, 0, 0, 0.5);
      .btn-con {
        width: 80px;
        color: white;
        font-size: 18px;
        text-align: center;
        margin-top: 25px;
        align-items: center;
      }
    }
  }
</style>
